import * as THREE from 'three'
export class Wall{
    constructor(scene,time){
        this.scene = scene;
        this.time = time;
        this.color = '#fab73f';

        this.config = {
            radius: 50,
            height: 50,
            open: false
        }
        this.createWall()
    }

    createWall(){
        const geometry = new THREE.CylinderGeometry(
            this.config.radius,
            this.config.radius,
            this.config.height,
            32,
            1,
            this.config.open
        )
        const material = new THREE.ShaderMaterial({
            uniforms:{
                u_color:{
                    value: new THREE.Color(this.color)
                },
                u_height:{
                    value: this.config.height
                },
                u_opacity:{
                    value: 0.6000
                },
                u_time: this.time
            },
            transparent: true,
            side:THREE.DoubleSide,
            vertexShader:`
                uniform float u_time;
                uniform float u_height;
                varying float v_opacity;
                void main(){
                    vec3 v_position = position * mod(u_time,1.0);
                    v_opacity = mix(1.0,0.0,position.y / u_height);
                    gl_Position = projectionMatrix * modelViewMatrix * vec4(v_position,1.0);
                }
            `,
            fragmentShader:`
                uniform vec3 u_color;
                uniform float u_opacity;
                varying float v_opacity;
                void main(){
                    gl_FragColor = vec4(u_color,u_opacity*v_opacity);
                }
            `
        })

        const mesh = new THREE.Mesh(geometry,material)
        mesh.position.set(0,25,0)
        this.scene.add(mesh)
    }
}